﻿var loadingDiv
var etlVars = {};
var trunPageObj;//翻页组件对像
$(initPage);
function initPage() {
	//初始化翻页组件
    trunPageObj =  $(".pageNext").turnPage(12, exportList);
	loadingDiv = $("<div style='display:none'><div style='width:100%;z-index:101;height:100%;background-color:#ccc;filter:alpha(Opacity=20);-moz-opacity:0.2;opacity: 0.2;position:absolute;top:0px;left:0px;'></div></div>").appendTo(jQuery(document.body));
	$("<div style='position:absolute;z-index:9999999;border:1px solid #eee;padding:20px 0 0 20px;width:390px;height:48px'/>").css({left:document.body.clientWidth/2-200,top:document.body.clientHeight/2-80}).append("<img width='200' height='15' src='" + BASE_PATH + "themes/comm/images/loading.gif' align='absmiddle'/>&nbsp;<font style='font-size:18px;color:#f30'>数据正在核对中……</font>").appendTo(loadingDiv);

	etlVars.etlProcID1 = $("#etlProcID1").val();
	etlVars.procStatus1 = $("#procStatus1").val();
	etlVars.busiDate1 = $("#busiDate1").val();
	
	etlVars.etlProcID2 = $("#etlProcID2").val();
	etlVars.procStatus2 = $("#procStatus2").val();
	etlVars.busiDate2 = $("#busiDate2").val();
	
	etlVars.etlProcID3 = $("#etlProcID3").val();
	etlVars.procStatus3 = $("#procStatus3").val();
	etlVars.busiDate3 = $("#busiDate3").val();
	
	//alert(etlVars.etlProcID1 + " " + etlVars.procStatus1 + " " + etlVars.busiDate1);
	//alert(etlVars.etlProcID2 + " " + etlVars.procStatus2 + " " + etlVars.busiDate2);
	//alert(etlVars.etlProcID3 + " " + etlVars.procStatus3 + " " + etlVars.busiDate3);
	initCheckInfo();
	$("#query").click(function() {
		//alert("step 1");
		$("#data_list").empty();
		trunPageObj.gotoPage(1);//搜索第一页
	});
	trunPageObj.gotoPage(1);//搜索第一页
	//生成数据
	$("#reCheck").click(function() {
		//alert("step 1");
		var busiDate = $("#busiDate").val();
		$("#reCheck").attr("disabled", true);//不允许再次操作
		if (etlVars.procStatus2 == "1"){
			alert("股份数据预处理运行中，请稍后再试！");
			$("#reCheck").attr("disabled", false);//允许再次操作
			return;
		}
		if (etlVars.procStatus3 == "1"){
			alert("股份数据核对运行中，请稍后再试！");
			$("#reCheck").attr("disabled", false);//允许再次操作
			return;
		}
  		if (etlVars.procStatus2 != "2" && !confirm(etlVars.busiDate2 + "：" + procDesc(etlVars.etlProcID2) + "：" + procStatus(etlVars.procStatus2) + "\n股份数据未正常预处理，是否核对股份数据？")) {
  			$("#reCheck").attr("disabled", false);//允许再次操作
			return;
		} else if (etlVars.procStatus3 == "2" && !confirm(etlVars.busiDate3 + "：" + procDesc(etlVars.etlProcID3) + "：" + procStatus(etlVars.procStatus3) + "\n股份核对已正常完成，是否重新核对股份数据？")) {
			$("#reCheck").attr("disabled", false);//允许再次操作
			return;
		}
		var taskInfo = busiDate + ":   ";
		taskInfo = taskInfo + "股份数据核对已开始，请耐心等待。";
		$("#taskInfo").html(taskInfo);
		
		loadingDiv.show();	
		$.post("m/stock_chk/check", {
			stockProc:"check",
			busiDate:busiDate,
            exchangeType : $$("exchangeTypeChk").value
		}, function(data) {
			loadingDiv.hide();
			$("#reCheck").attr("disabled", false);//允许再次操作
			if ($.checkErrorMsg(data) ) {
				alert(data.msg.text);
			} 
			location.reload();
		}, "json");
	});
	//生成数据
	$("#btnModifyNote").click(function() {
	    var url = BASE_PATH + "m/stock_chk/initModifyNote?id=" + $("#hidId").val();
	    window.showModalDialog(url,"","dialogWidth:800px;dialogHeight:480px;help:no;center:yes;status:yes");
	});
}

function initCheckInfo() {
	//信息内容
	var taskInfo = etlVars.busiDate2 + ":   ";
	if (etlVars.procStatus2 == '1') {
		taskInfo = taskInfo + "股份数据核对已开始，请耐心等待。";
	} else if  (etlVars.procStatus2 == '2') {
		taskInfo = taskInfo + "股份数据核对已成功完成。";
	} else if  (etlVars.procStatus2 == '3') {
		taskInfo = taskInfo + "股份数据核对已完成，但有警告发生。";
	} else if  (etlVars.procStatus2 == '9') {
		taskInfo = taskInfo + "股份数据核对已完成，但有错误发生。";
	} else if  (etlVars.procStatus2 == '0') {
		taskInfo = taskInfo + "股份数据核对未处理。";
	} 
	$("#taskInfo").html(taskInfo);
	
	if (etlVars.procStatus2 == '1'){
		loadingDiv.show();	
	}
}
function procDesc(etlProcID){
	var desc = "";
	if (etlProcID == "1"){
		desc = "股份数据采集";
	} else if (etlProcID == "2"){
		desc = "股份数据预处理";
	} else if (etlProcID == "3"){
		desc = "股份数据核对";
    } else if (etlProcID == "4"){
		desc = "股份数据归档";
	}
	return desc;
}
function procStatus(status){
	var desc = "";
	if (status == "0"){
		desc = "未处理";
	} else if (status == "1"){
		desc = "运行中";
	} else if (status == "2"){
		desc = "正常结束";
	} else if (status == "3"){
		desc = "警告结束";
	} else if (status == "9"){
		desc = "错误结束";
	}
	return desc;
}
function queryList() {
	//alert("F9:" + $$("F9").value);
	//alert("exchangeType:" + $$("exchangeType").value);
	//alert("diffType:" + $$("diffType").value);
	//alert("compType:" + $$("compType").value);
	
	$("#btnModifyNote").attr("disabled", true);
	var pageno=trunPageObj.getCurrentPageNo();//当前第几页
	var pagecount=trunPageObj.getPageCount();//一页多少条
	var busiDate = $("#busiDate").val();
	$.post("m/stock_chk/queryStockChk", {
		pageNo: pageno,
		pageSize : pagecount,
		queryDate : $.trim($("#queryDate").val()),
		stockAccount:$.trim($("#stockAccount").val()),
		stockCode:$.trim($("#stockCode").val()),
		diffType : $$("diffType").value,
		compType : $$("compType").value,
		exchangeType : $$("exchangeType").value
	}, function(data) {
		if ($.checkErrorMsg(data) ) {
			var fileList = "";
			if(data.stockChkPage && data.stockChkPage.dataList){
				var dataList = data.stockChkPage.dataList;
				$(dataList).each(function(i) {
					fileList += "<tr class='table_td_font' bgColor='#ffffff' onclick='selectTR(this)' objid='" + dataList[i].id + "'>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap >" + (dataList[i].branchNo ? dataList[i].branchNo:"") + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap >" + dataList[i].exchangeType + "</td>";
                    fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap >" + (dataList[i].taCode ? dataList[i].taCode : "") + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].stockAccount + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap >" + dataList[i].stockCode + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap >" + (dataList[i].fundAccount ? dataList[i].fundAccount : "") + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].dzAmount + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].hsAmount + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].diffType + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].compType + "</td>";
					fileList += "<td align='left'    height='25px' class='queryList_linebg' nowrap>" + (dataList[i].note ? dataList[i].note : "") + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].busiDate + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].formatOperTime + "</td>";
					fileList += "</tr>";
				});
			}
			$("#data_list").html(fileList);
			trunPageObj.setPageData(data.stockChkPage);
		} 
	}, "json");
}
//选中行
function selectTR(obj) {
	//修改背景色
	$(obj).attr("bgColor","#FAEBD7").siblings().attr("bgColor","#FFFFFF");
	$("#hidId").val($(obj).attr("objid"));
    	//alert($("#hidId").val());
	$("#btnModifyNote").attr("disabled", false);
}
function exportList() {
	var obj = window.showModalDialog(BASE_PATH + "page/export_select.jsp","","dialogWidth:200px;dialogHeight:80px;help:no;center:yes;status:no");
	if (obj) {
		//alert(BASE_PATH +"m/stock_chk/exportStockChk?queryDate=" + $.trim($("#queryDate").val()) + "&stockAccount=" + $.trim($("#stockAccount").val()) + "&stockCode=" + $.trim($("#stockCode").val()) + "&diffType=" + $.trim($("#diffType").val()) + "&compType=" + $.trim($("#compType").val()) + "&exchangeType=" + $.trim($("#exchangeType").val()) + "&expType=" + obj);
		window.open(BASE_PATH +"m/stock_chk/exportStockChk?queryDate=" + $.trim($("#queryDate").val()) + "&stockAccount=" + $.trim($("#stockAccount").val()) + "&stockCode=" + $.trim($("#stockCode").val()) + "&diffType=" + $$("diffType").value + "&compType=" + $$("compType").value + "&exchangeType=" + $$("exchangeType").value + "&expType=" + obj);
		//window.open("m/stock_chk/exportStockChk?queryDate=" + $.trim($("#queryDate").val()) + "&expType=" + obj);
	}
}
//下拉多选的onchange函数，此函数名不能改
function onchangeThisValue(thisName){
}
